package com.captjack.core.configuration;

import com.captjack.core.model._MappingKit;
import com.jfinal.plugin.IPlugin;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.hikaricp.HikariCpPlugin;

import java.util.ArrayList;
import java.util.List;

/**
 * Description description.....
 *
 * @author Jack Sparrow
 * @version 1.0.0
 * @date 2018/5/12 11:37
 * package com.captjack.wechat.configuration.plugin
 */
public class JfinalHikariCpPlugin {

    public static List<IPlugin> getHikariCpPlugin() {
        List<IPlugin> iPlugins = new ArrayList<IPlugin>();
        HikariCpPlugin hikariCpPlugin = new HikariCpPlugin("jdbc:mysql://127.0.0.1:3306/guns?characterEncoding=utf8&zeroDateTimeBehavior=convertToNull", "root", "root");
        hikariCpPlugin.setDriverClass("com.mysql.jdbc.Driver");
        iPlugins.add(hikariCpPlugin);
        /*
            ActiveRecrod支持插件。ActiveReceord中定义了
            addMapping(String tableName, Class<? extends Model> modelClass>)方法，
            该方法建立了数据库表名到Model的映射关系
         */
        ActiveRecordPlugin activeRecordPlugin = new ActiveRecordPlugin(hikariCpPlugin);
        activeRecordPlugin.addSqlTemplate("core/src/main/resources/all.sql");
        _MappingKit.mapping(activeRecordPlugin);
        iPlugins.add(activeRecordPlugin);
        return iPlugins;
    }

}
